package com.klb.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.klb.base.DaoBase;
import com.klb.dao.ReplyDao;
import com.klb.model.BbsReply;
import com.klb.tools.Tools;

/**
 * Created by fujia on 2016/6/6.
 */
public class ReplyDaoImpl extends DaoBase implements ReplyDao {

    
	@Override
    public List<BbsReply> getReplysByArticleId(int articleId) {
    	List<BbsReply> lists = null;
    	
        if (!Tools.objectIsNullOrNot(articleId)){
            Session session = this.hibernateSessionFactory.getCurrentSession();
            Transaction tx = null;
            String sql = "from BbsReply reply where reply.articleId = :articleId";

            try {
                tx = session.beginTransaction();

                Query query = session.createQuery(sql);
                query.setParameter("articleId", articleId);

                lists = query.list();

                tx.commit();
                
            } catch (Exception e){
                tx.rollback();
                e.printStackTrace();
            }
        }

        return lists;
    }


}
